<?php 
		
		include_once "Information.php";
		require_once("config/config.php");
		session_start();

		$schule=NULL;
		if(isset($_POST['login'])){
					$sqlConn = @new mysqli($host,$username,$password,$database);
					$user = (int)trim($_POST['user']);
					if(mysqli_connect_errno()){
						throw new Exception("Ein Fehler bei der SQL-Verbindung ist aufgetreten, Versuchen sie es erneut");
					}
					$result = $sqlConn->query("SELECT password FROM login WHERE schulid = ".$user);
					$row = $result->fetch_assoc();
					if(hash(sha256,$_POST['password']) == $row['password']){
						$row = NULL;
						$result->close();
						$sqlConn->close();
						$schule = new Information($user);
						$_SESSION['schule']=$schule;
						$_SESSION['login']=2;
						
						header("Location: home.php");
						exit();
					}
					else{
						$sqlConn->close();
						echo 'Falsche Login Daten<br>';
					}	
		}
?>
<html>
	<head>
	<title>
		No-Title
	</title>
	</head>
	<body>
		<form method="POST" action="<?php echo $_SERVER["SCRIPT_NAME"]; ?>">
		<table>
			<tr>
				<td>6-stellige Schulnummer:</td>
				<td>
					<input type="text" name="user" value=<?php echo '"'.$user.'"'; ?>>
				</td>
			</tr>
			<tr>
				<td>Passwort:</td>
				<td>
					<input type="password" name="password" value="">
				</td>
			</tr>
			<tr>
			 <td>
				<input type="submit" name="login" value="Login">
			</td>
			</tr>
		</table>
		</form>
	</body>
</html>
